
<template>
  <div class="grid _m-2">
    <div class="title d-flex justify-content-between">
      <h3>{{blocks.blockName}}</h3>
      <h3 @click="refreshData"><i class="iconfont icon-huanyihuan"></i> 换一换</h3>
    </div>
    <ul class="_m-2 d-flex  flex-wrap-wrap">
      <router-link :to="'/books/detail/' + books.id" tag="li" class="p-2" :key="books.id" v-for="books in blocks.booksVos.datas">
        <div class="book-cover">
          <img v-lazy="books.booksCover" alt="books cover">
        </div>
        <div class="book-info">
          <h3>{{books.booksName}}</h3>
          <p>{{books.author}}</p>
          <div class="outer">
            <p class="text">{{books.booksDescription}}</p>
          </div>
          <div class="book-tag">
            <span class="lz" v-if="books.isOver == '3.11.1'">连载</span>
            <span class="wj" v-else>完结</span>
          </div>
        </div>
      </router-link>
    </ul>
  </div>
</template>

<script>
import {findBooksByBlockId} from 'api/BlockApi'

export default {
  name: "GridFEight",
  props: {
    blockId: Number
  },
  data() {
    return {
      search: {
        id: this.blockId,
        currentIndex: 1,
        pageSize: 4
      },
      blocks: {}
    };
  },
  methods: {
    findBooksByBlockId() {
      findBooksByBlockId(this.search).then(res => {
        if(res.meta.success) {
          this.blocks = res.data;
        }
      });
    },
    refreshData () {
      this.search.currentIndex ++;
      if(this.search.currentIndex > this.blocks.booksVos.pagination.totalPage)
        this.search.currentIndex = 1
        
      this.findBooksByBlockId();
    }
  },
  created () {
    this.findBooksByBlockId();
  }
};
</script>

<style lang="stylus" scoped>
@import '~assets/css/style.styl';

.grid {
  background: #FFF;

  .title {
    height: 34px;
    font-size: 14px;
    line-height: 34px;

    h3 {
      padding-left: 3vw;
      padding-right: 2vw;
      position: relative;

      i {
        font-size: 12px !important;
        margin-right: 4px;
      }

      &:nth-child(1):after {
        content: '';
        width: 3px;
        height: 14px;
        display: inline-block;
        background: $colorPrimary;
        position: absolute;
        top: 10px;
        left: 1px;
        border-radius: 3px;
      }
    }
  }

  ul {
    li {
      max-width 45vw
      display: -webkit-box;
      

      .book-cover {
        width: 20vw;
        // height 26vw
        position: relative;
        overflow: hidden;

        img {
          display: block;
          position: absolute;
          top: 50%;
          left: 50%;
          -webkit-transform: translate(-50%,-50%);
          transform: translate(-50%,-50%);
          min-width: 100%;
          min-height: 100%;
          height: 100%;
        }
      }

      .book-info {
        margin-left 8px
        -webkit-box-flex: 1;
        h3 {
          color: #333;
          font-size: 16px;
          line-height: 16px;
          ellipsis()
        }

        p {
            font-size: 14px;
            line-height: 14px;
            color: #999;
            margin-top: 10px;
            max-height: 100%;
            ellipsis2()
        }
        div.outer {
          line-height: 16px;
          p.text {
            line-height: 18px;
          }
        }

        .book-tag {
          margin-top 3px

          span {
            font-size: 12px;
            height: 14px;
            line-height: 14px;
            border: 1px solid rgba(153,153,153,.3);
            border-radius: 2px;
            padding: 0 5px;
            margin-right: 5px;
            color: #999;
            display: inline-block;

            &.lz {
              color: #499fff;
              border-color: rgba(73,159,255,.3);
            }
            &.wj {
              color: #00c98d;
              border-color: rgba(0,201,141,.3);
            }
          }
        }
      }
    }
  }
}
</style>
